home *** CD-ROM | disk | FTP | other *** search
- /* use msc openfile /AL; link openfile environ getenv2;
- openfile.c
-
- This program impliments an open command for batch files.
- What OPENFILE does is remember a file name and initialize a file
- position. Both of these are saved as strings in the environment string.
- It is up to READFILE to re-open the file each time, position it in the
- right place, read a line, and update the position in the environment.
- To use OPENFILE in a batch file type:
-
- OPENFILE <handle> <pathname>
-
- handle is any unique identifer to keep track of this file.
- pathname is the name of the file to open.
-
- OPENFILE returns errorlevel=0 for failure, 1 for success
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <dos.h>
- #include <string.h>
-
- extern char *search_for(); /*searches environment for string*/
- extern del_string(); /*deletes a string from the environment*/
- extern int ins_string(); /*insert a new string in the environment*/
-
- char name[128]="n_"; /*space for the file name string*/
- char pos[64]="p_"; /*space for the file position string*/
-
- int envseg; /*segment of beginning of environment */
- char far *env; /*pointer to start of environment string*/
- extern unsigned int far getenv2(); /* routine to find environment and its size*/
- int enl; /*length of environment in bytes*/
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- int arg=1; /*where to look for arguments*/
- if (argc<2) /*do I have enough arguments?*/
- {
- printf("Usage: OPEN <handle> <pathname>\r\n");
- exit(0); /*exit if no file name*/
- }
- if (argc<3) /*if there is only one argument,*/
- arg=0; /*use it as the file name*/
- enl=getenv2(&envseg); /*get length and address of system environment*/
- FP_SEG(env)=envseg;
- FP_OFF(env)=0;
- strcat(name,argv[arg]); /*build the file name string*/
- strcat(name,"=");
- del_string(name); /*delete any old string with same handle*/
- strcat(name,argv[arg+1]);
- ins_string(name); /*insert this name into environment*/
- strcat(pos,argv[arg]); /*build the file position string*/
- strcat(pos,"=");
- del_string(pos); /*delete any old string with same handle*/
- strcat(pos,"0"); /*initial position is zero*/
- ins_string(pos); /*insert this into the environment*/
- exit(1);
- }
-
-